package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/permission")
public class PermissionController {


    @Reference
    private PermissionService permissionService;


    //查询权限列表功能呢
    @RequestMapping("/findAll")
    public Result findAll(){
        try{
            List<Permission> data = permissionService.findAll();
            return new Result(true,MessageConstant.QUERY_PERMISSION_SUCCESS,data);
        }catch(Exception e){
            return new Result(false, MessageConstant.QUERY_PERMISSION_FAIL);
        }

    }

    //获取当前角色包含的权限的id
    @RequestMapping("/findPermissionIds/{id}")
    public Result findPermissionIds(@PathVariable Integer id){

        List<Integer> list;
        try {
            //调用service层方法
            list = permissionService.findPermissionIds(id);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_PERMISSION_FAIL);
        }
        return new Result(true,MessageConstant.QUERY_PERMISSION_SUCCESS,list);
    }

}
